<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="layui/layui.js" type="text/javascript"></script>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
</head>
<body>

<script type="text/html" class="demoTable" id="myDiv">
    <div style="float: left">
        <div class="layui-btn-group">
            <button class="layui-btn " id="expand" lay-event="expand">全部展开</button>
            <button class="layui-btn " id="fold" lay-event="fold">全部折叠</button>
        </div>
    </div>
    <div class="layui-inline" style="float:right;height:29px;">
        <form id="searchform" lay-filter="searchform"
              class="layui-form layui-form-pane">
            <div class="layui-form">
                <div class="layui-form-item">
                    <label style="height: 32px;" class="layui-form-label">统计日期</label>
                    <div class="layui-inline">
                        <input type="text" style="height: 32px;" class="layui-input" id="test12" name ="netWorthDate" placeholder="日期" >
                    </div>
                        <button type="button"
                                class="layui-btn layui-btn-sm  " id="statisticsButton"  lay-filter="search" lay-event="search">
                            <i class="layui-icon">&#xe615;</i>统计
                        </button>
                        <button type="button" lay-event="search1" lay-filter="search1"
                                class="layui-btn layui-btn-sm " id="statisticsButton2" >
                            <i class="layui-icon">&#xe615;</i>查询
                        </button>
                </div>
            </div>
        </form>
    </div>

</script>
<script>
    layui.use(['table','treetable','laydate'], function () {
        var $ = layui.$;
        var table = layui.table;
        var form = layui.form;
        var laydate = layui.laydate;
        var treetable =layui.treetable;
        laydate.render({
            elem: '#test12' //指定元素
        });
        treetable.render({
            id:'testStock',
            treeColIndex: 1,
            treeSpid: -1,
            treeIdName: 'projectId',
            treePidName: 'projectFatherId',
            elem: '#trackone',
            toolbar: '#myDiv',//显示在表头的工具条
            url: 'selectNetWorth?netWorthDate=',
            page: false,
            cols: [[
                /*{type: 'numbers'},*/
                {type: 'checkbox'},
                {field: 'projectName', minWidth: 150, align: 'left',title: '项目名称'},
                {field: 'fundId', width: 150, align: 'center', title: '基金编号'},
                {field: 'projectCode', width: 150, align: 'center', title: '项目代码'},
                {field: 'shareNum', width: 150, align: 'center', title: '股数',templet: function (x) {
                        if(x.shareNum==0.00){
                            return "";
                        }
                        else{
                            return fmoney(x.shareNum,2);
                        }
                    }
                },
                {field: 'stopPrice', width: 150, align: 'center', title: '行情',templet: function (x) {
                        if(x.stopPrice==0){
                            return "";
                        }
                        else{
                            return fmoney(x.stopPrice,2);
                        }
                    }
                },
                {field: 'capital', width: 150, align: 'center', title: '成本',templet: function (x) {
                        if(x.capital==0.00){
                            return "";
                        }else if(x.projectName=='单位净值'){
                            return fmoney(x.capital,3);
                        }
                        else{
                            return fmoney(x.capital,2);
                        }
                    }
                },
                {field: 'marketValue', width: 150, align: 'center', title: '市值',templet: function (x) {
                        if(x.marketValue==0.00){
                            return "";
                        }
                        else{
                            return fmoney(x.marketValue,2);
                        }
                    }
                },
                {field: 'estimate', width: 150, align: 'center', title: '估值增值',templet: function (x) {
                        if(x.estimate==0.00){
                            return "";
                        }
                        else{
                            return fmoney(x.estimate,2);
                        }
                    }
                }
            ]],
            done: function () {
                // layer.closeAll('loading');
            }
        });
        table.on('toolbar(trackone)',function (obj) {
            var checkStatus=table.checkStatus(obj.config.id);//得到表格选中行的ID
            if (obj.event=='expand') {
                treetable.expandAll('#trackone');
            }else if (obj.event=='fold') {
                treetable.foldAll('#trackone');
            }
            if (obj.event=='search1'){
                alert("dhsi ");
                var netWorthDate = $("#test12").val();
                treetable.render({
                    treeColIndex: 1,
                    treeSpid: -1,
                    treeIdName: 'projectId',
                    treePidName: 'projectFatherId',
                    elem: '#trackone',
                    toolbar: '#myDiv',//显示在表头的工具条
                    url: 'selectNetWorth?netWorthDate='+netWorthDate,
                    page: false,
                    cols: [[
                        /*{type: 'numbers'},*/
                        {type: 'checkbox'},
                        {field: 'projectName', minWidth: 150, align: 'left',title: '项目名称'},
                        {field: 'fundId', width: 150, align: 'center', title: '基金编号'},
                        {field: 'projectCode', width: 150, align: 'center', title: '项目代码'},
                        {field: 'shareNum', width: 150, align: 'center', title: '股数',templet: function (x) {
                                if(x.shareNum==0.00){
                                    return "";
                                }
                                else{
                                    return fmoney(x.shareNum,2);
                                }
                            }
                        },
                        {field: 'stopPrice', width: 150, align: 'center', title: '行情',templet: function (x) {
                                if(x.stopPrice==0){
                                    return "";
                                }
                                else{
                                    return fmoney(x.stopPrice,2);
                                }
                            }
                        },
                        {field: 'capital', width: 150, align: 'center', title: '成本',templet: function (x) {
                                if(x.capital==0.00){
                                    return "";
                                }else if(x.projectName=='单位净值'){
                                    return fmoney(x.capital,3);
                                }
                                else{
                                    return fmoney(x.capital,2);
                                }
                            }
                        },
                        {field: 'marketValue', width: 150, align: 'center', title: '市值',templet: function (x) {
                                if(x.marketValue==0.00){
                                    return "";
                                }
                                else{
                                    return fmoney(x.marketValue,2);
                                }
                            }
                        },
                        {field: 'estimate', width: 150, align: 'center', title: '估值增值',templet: function (x) {
                                if(x.estimate==0.00){
                                    return "";
                                }
                                else{
                                    return fmoney(x.estimate,2);
                                }
                            }
                        }
                    ]],
                    done: function () {
                        // layer.closeAll('loading');
                        $("#test12").val(netWorthDate);
                    }
                });

            }else if(obj.event=='search'){
                alert("统计");
                var netWorthDate = $("#test12").val();
                treetable.render({
                    treeColIndex: 1,
                    treeSpid: -1,
                    treeIdName: 'projectId',
                    treePidName: 'projectFatherId',
                    elem: '#trackone',
                    toolbar: '#myDiv',//显示在表头的工具条
                    url:'insertNetWorth?netWorthDate='+$('#test12').val()+'&accountId=',
                    page: false,
                    cols: [[
                        /*{type: 'numbers'},*/
                        {type: 'checkbox'},
                        {field: 'projectName', minWidth: 150, align: 'left',title: '项目名称'},
                        {field: 'fundId', width: 150, align: 'center', title: '基金编号'},
                        {field: 'projectCode', width: 150, align: 'center', title: '项目代码'},
                        {field: 'shareNum', width: 150, align: 'center', title: '股数',templet: function (x) {
                                if(x.shareNum==0.00){
                                    return "";
                                }
                                else{
                                    return fmoney(x.shareNum,2);
                                }
                            }
                        },
                        {field: 'stopPrice', width: 150, align: 'center', title: '行情',templet: function (x) {
                                if(x.stopPrice==0){
                                    return "";
                                }
                                else{
                                    return fmoney(x.stopPrice,2);
                                }
                            }
                        },
                        {field: 'capital', width: 150, align: 'center', title: '成本',templet: function (x) {
                                if(x.capital==0.00){
                                    return "";
                                }else if(x.projectName=='单位净值'){
                                    return fmoney(x.capital,3);
                                }
                                else{
                                    return fmoney(x.capital,2);
                                }
                            }
                        },
                        {field: 'marketValue', width: 150, align: 'center', title: '市值',templet: function (x) {
                                if(x.marketValue==0.00){
                                    return "";
                                }
                                else{
                                    return fmoney(x.marketValue,2);
                                }
                            }
                        },
                        {field: 'estimate', width: 150, align: 'center', title: '估值增值',templet: function (x) {
                                if(x.estimate==0.00){
                                    return "";
                                }
                                else{
                                    return fmoney(x.estimate,2);
                                }
                            }
                        }
                    ]],
                    done: function () {
                        // layer.closeAll('loading');
                    }
                });
            }
        })
        table.on('tool(trackone)',function (obj) {
            var data = obj.data;
            alert(data)
        })


    });

    function fmoney(s, n)

    {

        n = n > 0 && n <= 20 ? n : 2;

        s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";

        var l = s.split(".")[0].split("").reverse(),

            r = s.split(".")[1];

        t = "";

        for(i = 0; i < l.length; i ++ )

        {

            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");

        }

        return t.split("").reverse().join("") + "." + r;

    }

</script>
<table id="trackone" lay-filter="trackone"></table>

</body>
</html>